<script>
import LoginViewVue from './pages/LoginView/LoginView.vue'

	export default {
		onLaunch: function() {
			console.log('App Launch')
			uni.onTabBarMidButtonTap(() => {
				if(uni.getStorageSync("token") === null || uni.getStorageSync("token") === ""){
					uni.showToast({
						icon:'error',
						title:"用户未登录",
						duration: 1000
					})
					uni.reLaunch({
						url:"/pages/UserView/UserView"
					})
				}else{
					const userId = uni.getStorageSync("userId")
					uni.chooseImage({
						count: 1, 
						sizeType: ['compressed'],
						sourceType: ['album','camera'],
						success: res => {
							var imageSrc = res.tempFilePaths[0];
							console.log(res.tempFilePaths[0]);
							uni.uploadFile({
								url: 'http://127.0.0.1:5000/get_recipe', //仅为示例，非真实的接口地址
								filePath: imageSrc,
								fileType: 'image',
								name: 'file',
								formData: {
									userid: userId,
								},
								success: (res) => {
									console.log(res);
									uni.navigateTo({
										url:"/pages/ResultView/ResultView"
									})
								}
							});
						}
					});
				}   
			})
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style>
	/*每个页面公共css */
	view,swiper,swiper-item{
		box-sizing: border-box;
	}
	.pageBg{
		background: 
			linear-gradient(to bottom, rgba(0, 0, 0, 0), #F2F2F4 900rpx),
			linear-gradient(to right, #fa709a 0%, #fee140 100%);
	}

</style>
